<?php 
abstract class Xml_Abstract {
    private $_entity = null;
    private $_strategry = null;
    private $_xml = '';

    /**
     * Constructor
     */
    public function __construct(Xml_Info_Abstract $_provider, Xml_Strategy_Abstract $_strategy) {
        $clsName = get_class($this);

        $funcName = sprintf("get%sInfo",str_replace('Xml_', '', $clsName));
        $this->_entity = $_provider->$funcName();
        $this->_strategy = $_strategy;
    }

    public function getXml() {
        return $this->_xml;
    }

    /**
     * 钩子函数，用于在策略为输出文件时候取的文件名.
     * @todo: 不足之处是该函数与策略绑定
     */
    public function getFileName() {
        throw new Xml_Exception('Unknown File Name');
    }

    protected abstract function _header($_aryInfo);
    protected abstract function _footer($_aryInfo); 
    protected abstract function _items($_aryInfo);

    public function output() {
        $this->_xml = '<?xml version="1.0" encoding="UTF-8"?>';
        $this->_xml .= $this->_header($this->_entity->header);
        $this->_xml .= $this->_items($this->_entity->items);
        $this->_xml .= $this->_footer($this->_entity->footer);
        return $this->_strategy->process($this);
    }
}
